<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
       table{
           margin: 0 auto;
           margin-top: 30px;
       }
    </style>
    </style>
</head>

<body>
    <div id="box"></div>
</body>

</html>
<script>
    var rows = prompt("请输入行数")
    var cols = prompt("请输入列数")
    var str=""
    str += "<table border='solid' width='400px' height='300px' cellspacing='0' cellpadding='0' margin-left=100px>";
    for (var i = 0; i < rows; i++) {

        str += "<tr>"; //循环取数组的值生成html代码
        for (var k = 0; k < cols; k++) {
            str += " <td>" + "</td>";
        }
        str += "</tr>";
    }

    str += "</table>";
    document.body.innerHTML= str
</script>